from fastapi import APIRouter, Depends, HTTPException
from readlater.utils.logger import get_logger
from readlater.chatlog import ChatlogManager
import requests
from typing import Optional

router = APIRouter()
logger = get_logger(__name__)


@router.get("/api/v1/article")
def get_articles():
    """
    获取聊天记录
    
    返回:
    - 聊天记录列表
    """
    chatlog_manager = ChatlogManager()

    # 发送请求到第三方API
    try:
        articles = chatlog_manager.read_articles()

        # 根据格式返回结果
        return {
            "status": "success",
            "data": articles,
            "total": len(articles)
        }
    except requests.RequestException as e:
        raise HTTPException(
            status_code=500,
            detail=f"请求失败: {str(e)}"
        )

